# -*- coding: utf-8 -*-
from django.contrib import admin
from models import Project, Release, Screenshot, Video, Poll, Vote
from pygameweb.comments.admin import CommentInline

class ProjectAdmin(admin.ModelAdmin):
    list_display = ("name", "is_inactive", "hide")
    search_fields = ['name']
    inlines = [CommentInline]
    fieldsets = (
        (None, {
            'fields': ('name',)
        }),
        ('Description', {
            'fields': ('markup', 'summary', 'description')
        }),
        ('Additional information', {
            'fields': ('homepage_link', 'tags')
        }),
        ('Team', {
            'classes': ('collapse',),
            'fields': (('admins', 'members'),)
        }),
        ('Flags', {
            'classes': ('collapse',),
            'fields': ('hide', 'is_inactive')
        }),
    )
    
    def save_model(self, request, obj, form, change):
        if not change:
            obj.creator = request.user
        obj.last_editor = request.user
        obj.save()    
    
class ReleaseAdmin(admin.ModelAdmin):
    list_display = ("project", "version", "created")
    list_display_links = ('project', 'version',)
    search_fields = ['project', 'version']
    fieldsets = (
        (None, {
            'fields': ('version',)
        }),
        ('Description', {
            'fields': ('markup', 'summary', 'changelog')
        }),
        ('Urls', {
            'fields': ('download_url', 'notes_url')
        }),
    )    

    def save_model(self, request, obj, form, change):
        if not change:
            obj.creator = request.user
        obj.last_editor = request.user
        obj.save()

    
class ScreenshotAdmin(admin.ModelAdmin):
    list_display = ("name", "project", "preview")

    fieldsets = (
        (None, {
            'fields': (('name','public'), 'project',
                       'image', 'uploaded_by', 'description',
                       )
        }),
    )    

class VideoAdmin(admin.ModelAdmin):
    list_display = ("name", "project", "preview")


admin.site.register(Project, ProjectAdmin)
admin.site.register(Release, ReleaseAdmin)
admin.site.register(Screenshot, ScreenshotAdmin)
admin.site.register(Video, VideoAdmin)
admin.site.register(Poll)
admin.site.register(Vote)

